//
//  BIDExpressQueryViewController.m
//  HJGJCommunity
//
//  Created by mal on 2017/6/10.
//  Copyright © 2017年 mal. All rights reserved.
//

#import "BIDExpressQueryViewController.h"
#import "BIDExpressCompanyListViewController.h"
#import "BIDLoadWebPageViewController.h"
#import "BIDDataCommunication.h"

@interface BIDExpressQueryViewController ()<BIDExpressCompanyListViewControllerDelegate>
{
    NSString *_companyCode;
}
@end

@implementation BIDExpressQueryViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.title = @"快递查询";
    _numberTF.inputAccessoryView = self.toolBar;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)showExpressCompany:(id)sender
{
    BIDExpressCompanyListViewController *vc = [[BIDExpressCompanyListViewController alloc] init];
    vc.delegate = self;
    [self.navigationController pushViewController:vc animated:YES];
}

- (IBAction)queryBtnHandler:(id)sender
{
    [_numberTF resignFirstResponder];
    NSString *strExpressNumber = _numberTF.text;
    if(strExpressNumber.length > 0)
    {
        BIDLoadWebPageViewController *vc = [[BIDLoadWebPageViewController alloc] initWithNibName:@"BIDLoadWebPageViewController" bundle:nil];
        //NSString *strRequestURL = [[NSString alloc] initWithFormat:@"https://www.kuaidi100.com/chaxun?com=%@&nu=%@", _companyCode, strExpressNumber];
        NSString *strRequestURL = [[NSString alloc] initWithFormat:@"https://m.kuaidi100.com/index_all.html?type=%@&postid=%@", _companyCode, strExpressNumber];
        NSLog(@"%@", strRequestURL);
        vc.webURL = strRequestURL;
        [self.navigationController pushViewController:vc animated:YES];
    }
    else
    {
        [self showAlertView:@"请填写快递单号" buttonTitle:ALERT_BTN_TITLE tag:0 functionName:nil];
    }
}

#pragma mark - BIDExpressCompanyListViewControllerDelegate
- (void)fetchExpressCompanyName:(NSString *)companyName code:(NSString *)companyCode
{
    _nameTF.text = companyName;
    _companyCode = companyCode;
}

@end
